package com.lyf.network.practice.practice_6_28;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author LYF
 * @date 2022/6/28
 */
public class TcpBioClient {
    static void startClient() throws IOException {
        Socket socket = new Socket("127.0.0.1",8848);
        System.out.println("start client::");
        while (true){
            OutputStream outputStream = socket.getOutputStream();
            Scanner scanner = new Scanner(System.in);
            String input;
            System.out.println("please input::");

            input = scanner.nextLine();
            outputStream.write(input.getBytes());
//        while (!(input=scanner.nextLine()).equals("exit")){
//            outputStream.write(input.getBytes());
//        }

            InputStream inputStream = socket.getInputStream();
            // System.out.println("received::");
            int len =0;
            byte[]data=new byte[1024];
            len = inputStream.read(data);
            System.out.println("received::");
            System.out.println(new String(data,0,len));
//        while((len=inputStream.read(data))!=-1){
//            System.out.println(new String(data,0,len));
//        }

//            inputStream.close();
//            outputStream.close();

        }


        //socket.close();

    }

    public static void main(String[] args) throws IOException {
        startClient();
    }
}
